{% extends "bootstrap/base.html" %}
{% block title %} load {% endblock %}
{% block scripts %}
    <script src="/pages/site/index/index.js"></script>
    <script src="http://issues.wenzhixin.net.cn/bootstrap-table/assets/jquery.min.js"></script>
    <script src="/static/js/BootstrapTable/bootstrap-table.min.js"></script>
    <script src="/static/js/BootstrapTable/bootstrap-table-locale-all.min.js"></script>
    {{super()}}
{% endblock %}
{% block styles %}
    {{super()}}
    <link rel="stylesheet" href="/pages/site/index/index.css"/>
    <link rel="stylesheet" href="/static/js/BootstrapTable/bootstrap-table.min.css"/>
{% endblock %}
{% block page_content %}
    <div class="container">
        <h1>load</h1>
        <p>Load the data to table, the old rows will be removed: <code>$table.bootstrapTable('load', data);</code></p>
        <div id="toolbar">
            <button id="button" class="btn btn-default">load</button>
        </div>
        <table id="table"
               data-toggle="table"
               data-toolbar="#toolbar"
               data-height="460"
              >
            <thead>
            <tr>
                <th data-field="id">ID</th>
                <th data-field="name">Item Name</th>
                <th data-field="price">Item Price</th>
            </tr>
            </thead>
        </table>
    </div>
<script>
    var $table = $('#table'),
        $button = $('#button');
    $(document).init(function () {
            $table.bootstrapTable('load', randomData());
            $button.click(function () {
                $table.bootstrapTable('load', randomData());
            });
    });

    function randomData() {
        var startId = ~~(Math.random() * 100),
            rows = [];

        for (var i = 0; i < 10; i++) {
            rows.push({
                id: startId + i,
                name: 'test' + (startId + i),
                price: '$' + (startId + i)
            });
        }
        return rows;
    }
</script>
{% endblock %}
